#
# Load and manage all the file parsers.
#
# Auther: Wesley Liu
# Email: jinvy.liu@gmail.com
# Date: 12/19/2007
#

class ParserManager
    attr_reader :parsers
    
    def initialize
        @parsers = Hash.new
        Dir[File.dirname(__FILE__) + '/*.rb'].each do |entry|
            IO.foreach(entry) do |line|
                if /\s*class\s+(\S+)\s+<\s+IFileParser/ =~ line
                    load entry
                    instance = eval($1 + '.new')
                    if instance
                        @parsers[instance.for.downcase] = instance
                    end
                    break
                end
            end
        end
    end
    
    def parse filename, progressTarget
        parser = @parsers[filename.split('.').reverse[0].downcase]
        parser.parse filename, progressTarget
    end
end

if __FILE__ == $0
    puts ParserManager.new.parsers.length
    ParserManager.new.parsers.each {|key, value| puts key }
end